﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using Model;
using BLL;
using DBUtility;

namespace IYASAKATools
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string strHPHM = txtHPHM.Text.Trim();
            DataTable dtResult = new DataTable();

            string strSql = "select top 10(case substring(JCLSH,1,1) when 'A' then '安检' when 'Z' then '综检' when 'P' then '排放' end) as JYLB,JCLSH, ID, HPHM, HPZL,CLXXSJ , JYXM from RESULT_VEHICLE_INFO where HPHM like '%" + strHPHM + "%' order by ID desc";

            DbHelper.GetTable(strSql, ref dtResult);

            if (dtResult.Rows.Count > 0)
            {
                for (int i = 0; i < dtResult.Rows.Count; i++)
                {
                    string[] strJYXM = dtResult.Rows[i]["JYXM"].ToString().Split(',');
                    string strJYXM_C = "";
                    for (int j = 0; j < strJYXM.Length; j++)
                    {
                        if (string.IsNullOrEmpty(strJYXM[j]) == false)
                        {
                            strJYXM_C += getXMName(strJYXM[j]) + ",";
                        }

                    }
                    dtResult.Rows[i]["JYXM"] = strJYXM_C;
                }

                dataGridView.DataSource = dtResult;
                dataGridView.Columns[0].MinimumWidth = 80;
                dataGridView.Columns[1].MinimumWidth = 250;
                dataGridView.Columns[2].MinimumWidth = 50;
                dataGridView.Columns[3].MinimumWidth = 100;
                dataGridView.Columns[4].MinimumWidth = 100;
                dataGridView.Columns[5].MinimumWidth = 100;
                dataGridView.Columns[6].MinimumWidth = 500;
            }
            else
            {
                dataGridView.DataSource = null;
            }

        }

        protected string getXMName(string code)
        {
            string result = "";
            result = DbHelper.GetValue("SELECT CON_CON from const_define where CON_CHNAME='jyxm' and CON_CODE='" + code + "'");
            return result;
        }

        private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if(e.RowIndex >=0)
            {
                string strJCLSH = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
                FrmData frmData = new FrmData(strJCLSH);
                frmData.ShowDialog();
            }
        }
    }
}
